<?php

use think\migration\Migrator;
use think\migration\db\Column;

class AdminUsers extends Migrator
{
    /**
     * Change Method.
     *
     * Write your reversible migrations using this method.
     *
     * More information on writing migrations is available here:
     * http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
     *
     * The following commands can be used in this method and Phinx will
     * automatically reverse them when rolling back:
     *
     *    createTable
     *    renameTable
     *    addColumn
     *    renameColumn
     *    addIndex
     *    addForeignKey
     *
     * Remember to call "create()" or "update()" and NOT "save()" when working
     * with the Table class.
     */
    public function change()
    {
        $table  =  $this->table('admin_users');
        $table->addColumn('user_name', 'string',array('limit'  =>  50,'default'=>'','comment'=>'用户昵称'))
            ->addColumn('account', 'string',array('limit'  =>  50,'default'=>'','comment'=>'账号'))
            ->addColumn('password', 'string',array('limit'  =>  50,'default'=>md5('123456'),'comment'=>'密码'))
            ->addColumn('email', 'string',array('limit'  =>  50,'default'=>'','comment'=>'邮箱'))
            ->addColumn('status', 'integer',array('limit'  =>  1,'default'=>1,'comment'=>'状态1正常  2冻结'))
            ->addColumn('role', 'integer',array('limit'  =>  11,'default'=>0,'comment'=>'角色ID'))
            ->addColumn('last_login_time', 'datetime',array('default'=>null,'comment'=>'最近一次登录时间'))
            ->addColumn('create_time', 'datetime',array('default'=>null,'comment'=>'创建时间'))
            ->addColumn('update_time', 'datetime',array('default'=>null,'comment'=>'更新时间'))
            ->addColumn('delete_time', 'datetime',array('default'=>null,'comment'=>'删除时间'));

        $table->insert([
            'account' => 'admin',
            'user_name' => 'admin',
            'role' => 1,
            'create_time' => date('Y-m-d H:i:s'),
            'update_time' => date('Y-m-d H:i:s'),
        ]);

        $table->save();
    }
}
